require.config({
    paths: {
        'domReady': 'src/lib/require/domReady',
        'text': 'src/lib/require/text',
        'css': 'src/lib/require/require-css',

        'jquery': 'src/lib/jquery/jquery',

        'layui': 'src/lib/layui/layui.all',

        'knockout': 'src/lib/knockout/knockout',
        'ko.mapping': 'src/lib/knockout/knockout.mapping',
        'ko.validation': 'src/lib/knockout/knockout.validation',
        'ko.validation.zh-CN': 'src/lib/knockout/zh-CN',
        'ko.amd': 'src/lib/knockout/knockout-amd-helpers',
        'ko.projections': 'src/lib/knockout/knockout-projections',

        'lego.tool': 'src/lib/lego/lego.tool',
        'lego.ko': 'src/lib/lego/lego.ko'
    },
    shim: {
        'layui': {
            exports: 'layui'
        },
        'knockout': {
            deps: ['jquery'],
            exports: 'ko'
        },
        'ko.mapping': {
            deps: ['knockout']
        },
        'ko.validation': {
            deps: ['knockout']
        },
        'ko.validation.zh-CN': {
            deps: ['ko.validation']
        },
        'ko.amd': {
            deps: ['knockout', 'text']
        },
        'ko.projections': {
            deps: ['knockout']
        },

        'lego.ko': {
            deps: ['ko.amd']
        }
    },
    deps: ['knockout', 'ko.mapping'], callback: function (ko, koMapping) {
        ko.mapping = koMapping;
    }
});

define('initLib', function (require) {
    require('jquery');
    window.ko = require('knockout');
    require('ko.mapping');
    require('ko.validation');
    require('ko.amd');
    require('ko.projections');

    require('layui');

    require('lego.ko');

    ko.amdTemplateEngine.defaultPath = "/";
});

require(['domReady!', 'initLib', 'css!src/lib/layui/css/layui.css', 'css!custom.css'], function () {
    var viewModel = {
        systemTitle: '内蒙古食药环侦业务系统',
        footer: '© 内蒙古食药环侦部门  -  技术支持：内蒙古慧瑞系统集成有限公司',
        topMenu: [
            {name: '案件管理', url: 'template/anJian/index', children: []},
            {name: '情报管理', url: '', children: []}
        ]
    };

    viewModel.currentPage = ko.observable('demo/base');
    viewModel.currentTopMenu = ko.observable(viewModel.topMenu[0]);

    viewModel.clickTopMenu = function (currentMenu, event) {
        viewModel.currentTopMenu(currentMenu);
        var parentMenu = $(event.target).parents('.layui-nav-item');
        if (parentMenu.length > 0) {
            setTimeout(function () {
                parentMenu.addClass('layui-this');
            }, 300);
        }
        var childrenMenu = $(event.target).next().children('dd');
        if (childrenMenu.length > 0) {
            childrenMenu.removeClass('layui-this');
        }
    };

    ko.applyBindings(viewModel);
    setTimeout(function () {
        layui.element.render();
    }, 300);
});